/*
 * COPYRIGHT:	2010 Christopher Smith, licenced under the GNU GPL v2; see COPYING in the top level directory
 * PROJECT:		sdedit
 * FILE:		acluialt ppage.cpp
 * PURPOSE:		SdeCreateSecurityPage() property page support
 */

namespace Acluialt
{
	struct EditSecurityObj;

	void DeleteEditSecurityObj(EditSecurityObj *Eso);
	void OpenEditSecurityObj(EditSecurityObj *Eso, HWND Parent);

	UINT CALLBACK PPageProc(HWND Dlg, UINT Msg, PROPSHEETPAGE *Sheet)
	{
		__try
		{
			switch(Msg)
			{
			case PSPCB_CREATE:
				break;

			case PSPCB_RELEASE:
				DeleteEditSecurityObj((EditSecurityObj *)Sheet->lParam);
				break;
			}

			return TRUE;
		}
		__except(ShowErrorMessageBox(exception_info(), Dlg))
		{
			return FALSE;
		}
	}

	INT_PTR PPageDlgPrc(HWND Dlg, UINT Msg, WPARAM wparam, LPARAM lparam)
	{
		__try
		{
			PCWSTR EsoProp = L"SdEdit EditSecurityObj";

			if(Msg == WM_INITDIALOG)
			{
				PROPSHEETPAGE *Page = (PROPSHEETPAGE *)lparam;

				SetProp(Dlg, EsoProp, (HANDLE)Page->lParam); //lparam == Eso

				return TRUE;
			}

			if(Msg == WM_COMMAND && HIWORD(wparam) == BN_CLICKED && LOWORD(wparam) == IDC_EDIT_SEC)
			{
				EditSecurityObj *Eso = (EditSecurityObj *)GetProp(Dlg, EsoProp);
				OpenEditSecurityObj(Eso, Dlg);

				return TRUE;
			}

			if(Msg == WM_DESTROY)
			{
				RemoveProp(Dlg, EsoProp);

				return TRUE;
			}
		}
		__except(ShowErrorMessageBox(exception_info(), Dlg))
		{}

		return FALSE;
	}

	void InitPage(PROPSHEETPAGE *Sheet, EditSecurityObj *Eo)
	{
		RtlZeroMemory(Sheet, sizeof *Sheet);
		Sheet->dwSize = sizeof *Sheet;

		Sheet->pszTitle = L"Security";

		Sheet->dwFlags = PSP_USECALLBACK | PSP_USETITLE;
		Sheet->pfnCallback = &PPageProc;

		Sheet->pfnDlgProc = &PPageDlgPrc;

		Sheet->hInstance = SdEditGModule;
		Sheet->pszTemplate = MAKEINTRESOURCE(IDD_ACLUIALT_EDITSEC);
		Sheet->lParam = (LPARAM)Eo;
	}

}//namespace Acluialt